<template>
    <view>
		
		<view class="cu-list menu sm-border" >
			<block v-if="showMenu">
				<view class="cu-item arrow" @click="handlerAbout">
					<view class="content">
						<text class="cuIcon-emoji text-blue"></text>
						<text class="text-black">关于我们</text>
					</view>
				</view>
				<view class="cu-item arrow" @click="creator">
					<view class="content">
						<text class="cuIcon-edit text-blue"></text>
						<text class="text-black">创作者协议</text>
					</view>
				</view>
				<view class="cu-item arrow" @click="agreementClick">
					<view class="content">
						<text class="cuIcon-profile text-blue"></text>
						<text class="text-black">用户协议</text>
					</view>
				</view>
				<view class="cu-item arrow" @click="policyClick">
					<view class="content">
						<text class="cuIcon-sponsor text-blue"></text>
						<text class="text-black">隐私政策</text>
					</view>
				</view>
			</block>
			<view class="cu-item arrow" @click="handlerClearCache">
				<view class="content">
					<text class="cuIcon-delete text-blue"></text>
					<text class="text-black">清除缓存</text>
				</view>
			</view>
			<view class="cu-item arrow" v-if="isLogin" @click="logout">
				<view class="content" >
					<text class="cuIcon-roundclose text-blue"></text>
					<text class="text-black">退出登录</text>
				</view>
			</view>
			
		</view>
		<view class="tishi" v-if="showMenu">
			免责声明：本站内容来自用户投稿，如涉及版权问题，请随时联系告知我们。
			联系邮箱：2549789059@qq.com
		</view>

    </view>
</template>

<script>
/*
 * Author: 郭少
 * github: https://github.com/guoshao99/wallpaper-applet
 * gitee: https://gitee.com/guoshao99/wallpaper-applet
 * QQ：2549789059
 * 微信：2549789059
 */

const Authentication = require('../../utils/authentication.js');

const http = require('../../utils/http.js');

const Constants = require('../../utils/constants.js');


export default {

    data() {
        return {
			isSuccess:Authentication.getIsSuccess(),
			user:Authentication.getMiniUser(),
			isLogin:Authentication.isLogin(),
			showMenu: Constants.SHOW_MEUN
        };
    },
    onLoad() {
        let that = this; //配置信息  begin
		
    },
    onShow: function (options) {
        this.setData({
            user: Authentication.getMiniUser(),
			isLogin:Authentication.isLogin(),
			isSuccess:Authentication.getIsSuccess()
        });
    },

    methods: {

		creator(){
			uni.navigateTo({
				url:'/pages/about/creAgreement'
			})
		},
		agreementClick(){
			uni.navigateTo({
				url: '/pages/about/agreement'
			})
		},
		policyClick(){
			uni.navigateTo({
				url: '/pages/about/policy'
			})
		},
		//退出登录
		logout:function(){
			let that = this;
			uni.showModal({
				title:'提示',
				content:'确定退出登录吗?',
				cancelText:'取消',
				confirmText:'确定',
				 success(res){
				  if(res.cancel){
					
				  }else if(res.confirm){
					uni.showLoading({
						title:'正在退出'
					})  
					
					//请求后台退出接口
					var params = {
						baseUrl:true,
					    url: '/p/user/logout',
					    method: 'GET',
					    data: {
					    },
					    callBack: function (res) {
					        if(res){
								setTimeout(function(){
									uni.hideLoading()
									uni.showToast({
										title:'退出成功',
									})
									Authentication.clearCache();
									that.isLogin = false;
									uni.navigateBack({
										
									})
								},1000)
							}
					    },errCallBack:function(error){
							uni.showToast({
								title:'退出成功',
							})
							Authentication.clearCache();
						}
					};
					http.request(params);
				  }
				}
			})
		},



        handlerAbout: function (e) {
            uni.navigateTo({
                url: '/pages/about/about'
            });
        },


        handlerClearCache: function (e) {
            uni.showModal({
                title: '提示',
                content: '确定清除缓存吗？',
                success(res) {
                    if (res.confirm) {
                        //Authentication.clearCache();
                        uni.showToast({
                            title: '清除成功'
                        });
                        // uni.reLaunch({
                        //     url: '/pages/index/index'
                        // });
                    }
                }
            });
        },

    }
};
</script>

<style>
	
	@import './setup.css';
	
	.tishi{
		color: #b9b9b9;
		padding: 15px;
		bottom: 15px;
		position: absolute;
		font-size: 12px;
	}
</style>
